package org.third.security.crypto;

import java.security.Provider;
import java.security.Provider.Service;
import java.security.Security;
import java.util.Set;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
import org.junit.Test;

public class JasyptProviderTst {

    @Test
    public void test001() {
        System.setProperty("java.security.debug", "all");

        // 加密器
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        // 加密配置
        EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
        // org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible
        // cause is you are using strong encryption algorithms and you have not installed the Java Cryptography
        // Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine
        config.setAlgorithm("PBEWithMD5AndTripleDES");
        // 自己在用的时候更改此密码
        config.setPassword("apdplat");
        // 应用加密配置 DES算法
        encryptor.setConfig(config);

        String plaintext = "root";
        // 加密
        String ciphertext = encryptor.encrypt(plaintext);

        System.out.println(plaintext + "==>" + ciphertext);

        String result = encryptor.decrypt(ciphertext);
        System.out.println(ciphertext + "==>" + result);
    }
}
